#!/bin/bash
Default=index
Src='https://dapse.googlecode.com/svn/trunk'
Files="index.cgi"

Q=${QUERY_STRING:=$Default}
Q=$(echo $Q | sed 's/[^\.0-9a-zA-Z]//g')

echo "Content-type: text/html"
echo ""

main() {
	if [ "$Q" = "REFRESH" ]
	then
		for i in $Files; do
			wget -q -O - $Src/$i > $i
		done
		chmod 755 index.cgi
		echo "<pre>"; echo ""; date
		cksum  $Files
		echo "`cat $Files | cksum` TOTAL"
		echo '<a href="http://dapse.unbox.org">Continue.</a>'
	else
		header $Q
		wget -q -O - $Src/site/${Q} | 
		PATH="$PATH:/home/stuff/env/bin" markdown_py  
		wget -q -O - $Src/footer.html
	fi
}
header() { cat<<-EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html 	xmlns="http://www.w3.org/1999/xhtml" 
		xml:lang="en" 
		lang="en">
<head>   
<meta 	http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link 	rel="stylesheet" 
		href="https://dapse.googlecode.com/svn/trunk/img/style.css" 
		type="text/css" />
<link 	rel="icon" 
		href="https://dapse.googlecode.com/svn/trunk/img/greend.png" 
		type="image/png"/>
<title>	DAPSE: $1
		</title>
</head>
<body>
<div id="wrap">
  <div id="header">
    <h1 id="logo-text">Data Analysis<span class="gray">Patterns</span></h1>
    <h2 id="slogan">in software engineering</h2>
  </div>
  <div id="header-tabs">
    <ul>
      <li><a href="http://dapse.unbox.org"><span>Home</span></a></li>
      <li><a href="?patterns"><span>Patterns</span></a></li>
      <li><a href="?news"><span>News</span></a></li>
      <li><a href="?links"><span>Links</span></a></li>
      <li><a href="?projects"><span>Projects</span></a></li>
      <li><a href="?workflow"><span>Contribute</span></a></li>
      <li><a href="?contact"><span>Contact us</span></a></li>
    </ul>
  </div>
  <div id="content-wrap">
    <div id="main"> <a name="TemplateInfo"></a>
EOF
}
main
